﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mamnontuoitho7.AppCode;
using System.Data;
using System.Text.RegularExpressions;

namespace mamnontuoitho7.module
{
    public partial class KidDetails : System.Web.UI.Page
    {
        protected Kid _kid = new Kid();
        protected Teacher _teacher = new Teacher();
        protected General _general = new General();

        protected DataRow _dtrKid;
        protected String _kidID = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["memberID"].ToString() != "" && (Session["role"].ToString() == "3" || Session["role"].ToString() == "4"))
            {

                try
                {
                    if (Request.QueryString["KidID"] != null && Request.QueryString["KidID"] != "")
                    {
                        _kidID = Request.QueryString["KidID"].ToString();

                        Match match = Regex.Match(_kidID, @"([0-9])$");
                        //If kidID is greater than 6 character
                        if (_kidID.Length > 6 || !match.Success)
                        {
                            return;
                        }

                        //Check Teacher or Parent view kid details
                        if (Session["role"].ToString() == "3")
                        {
                            _dtrKid = _kid.GetKidInformationOfClass(_kidID, Session["classID"].ToString());
                        }
                        else if (Session["role"].ToString() == "4")
                        {
                            _dtrKid = _kid.GetKidInformationOfParent(_kidID, Session["memberID"].ToString());
                        }

                        if (_dtrKid == null)
                        {
                            return;
                        }


                        //Get Kid information
                        lblFullName.Text = _dtrKid["KidLastName"].ToString() + " " + _dtrKid["KidFirstName"].ToString();
                        lblBirthday.Text = _dtrKid["KidBirthday"].ToString();
                        lblSex.Text = _dtrKid["KidBirthday"].ToString() == "1" ? "Name" : "Nữ";
                        lblFather.Text = _dtrKid["Father"].ToString();
                        lblMother.Text = _dtrKid["Mother"].ToString();
                        lblClass.Text = _dtrKid["ClassName"].ToString() + ", Khối: " + _dtrKid["ClassCategoryName"].ToString();
                        lblClassPosition.Text = _dtrKid["ClassPosition"].ToString();
                        imgKid.ImageUrl = "../images/avatar/kid/" + (_dtrKid["KidAvatar"].ToString() == "" ? ConstantClass._kidDefaultAvatar : _dtrKid["KidAvatar"].ToString());
                        lblVisible.Text = _dtrKid["KidVisible"].ToString().ToLower() == "true" ? "Đang học ở trường" : "Đã ra trường";

                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Response.Redirect(ConstantClass._errorLoginPage);
                }

            }
            else
            {
                Response.Redirect(ConstantClass._errorLoginPage);
            }
            Session["Common_articleTypeID"] = "1";

        }

    }
}